package com.xh.core.bean;

import com.xh.core.constant.AjaxResultConstant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

@ApiModel(value = "ajaxResult", description = "Ajax通用返回对象")
@Data
/**
 * ajax请求返回对象
 */
public class AjaxResult {

    @ApiModelProperty(value = "返回结果",notes ="成功：true，失败：false" ,dataType = "Boolean", required = true)
    private boolean result;
    @ApiModelProperty(value = "错误代码",notes ="成功：0" ,dataType = "Integer", required = true)
    private int errorCode;
    @ApiModelProperty(value = "异常信息",notes ="接口调用失败时，显示错误信息" ,dataType = "String", required = false)
    private String msg="";
    @ApiModelProperty(value = "JSON对象",notes ="返回的JSON数据对象" ,required = true)
    private Object json;
    @ApiModelProperty(value = "重定向链接",notes ="需要重定向操作时，返回重定向地址" ,dataType = "String", required = false)
    private String redirectUrl="";

    public AjaxResult(boolean result){
        this.result=result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=AjaxResultConstant.ErrorCode.UN_KNOWEN;
        }
    }

    public AjaxResult(boolean result, String msg) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=AjaxResultConstant.ErrorCode.UN_KNOWEN;
        }
        this.msg = (msg==null?"":msg);
    }

    public AjaxResult(boolean result, Object json) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=AjaxResultConstant.ErrorCode.UN_KNOWEN;
        }
        this.json = json;
    }

    public AjaxResult(boolean result, String msg, Object json) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=AjaxResultConstant.ErrorCode.UN_KNOWEN;
        }
        this.msg = msg;
        this.json = json;
    }

    public AjaxResult(boolean result, String msg, Object json, String redirectUrl) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=AjaxResultConstant.ErrorCode.UN_KNOWEN;;
        }
        this.msg = msg;
        this.json = json;
        this.redirectUrl = redirectUrl;
    }


    public AjaxResult(boolean result, int errorCode, String msg) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=errorCode;
        }
        this.msg = (msg==null?"":msg);
    }

    public AjaxResult(boolean result, int errorCode, String msg, Object json) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=errorCode;
        }
        this.msg = msg;
        this.json = json;
    }

    public AjaxResult(boolean result, int errorCode, String msg, Object json, String redirectUrl) {
        this.result = result;
        if(this.result){
            this.errorCode= AjaxResultConstant.ErrorCode.NO_ERROR;
        }else{
            this.errorCode=errorCode;
        }
        this.msg = msg;
        this.json = json;
        this.redirectUrl = redirectUrl;
    }
}
